package com.wx.controller;

import com.alibaba.fastjson.JSONObject;
import com.wx.model.CompanyModel;
import com.wx.service.ICompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpSession;


@RestController
@RequestMapping("/company")
public class companyController {

    @Autowired
    ICompanyService iCompanyService;

    @GetMapping("/findAll")
    public JSONObject findAll(){
        CompanyModel list=iCompanyService.findAll();
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("list",list);
        return jsonObject;
    }

    @PostMapping("/findById")
    public JSONObject findById(@RequestBody CompanyModel companyModel, HttpSession session){
        CompanyModel companyModel1=iCompanyService.findById(companyModel);
        String logo=companyModel1.getLogo();
        session.setAttribute("logo",logo);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("companyModel",companyModel1);
        return jsonObject;
    }


    @PostMapping("/update")
    public JSONObject update(@RequestBody CompanyModel companyModel){
        int result = iCompanyService.update(companyModel);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", result);
        return jsonObject;
    }
}
